// 设置mapping
DELETE beijin

PUT /beijin
{
  "mappings": {
    "properties": {
      "geometry": {"type": "geo_shape"},
      "properties": {
          "properties": {
              "adcode": {"type": "integer"},
              "level": {"type": "keyword"},
              "centroid": {"type": "geo_point"},
              "center": {"type": "geo_point"}
          }
      }
    }
  }
}

DELETE beijin

PUT /beijin
{
    "mappings": {
        "properties": {
            "geometry": {
                "type": "keyword",
                "store": true
            },
            "properties": {
                "properties": {
                    "adcode": {
                        "type": "integer"
                    },
                    "level": {
                        "type": "keyword"
                    },
                    "centroid": {
                        "type": "geo_point"
                    },
                    "center": {
                        "type": "geo_point"
                    }
                }
            }
        }
    }
}

// 导入data.json
// curl -X POST "elasticsearch:9200/_bulk" -H 'Content-Type: application/json' --data-binary @data.json
// 数据来自 https://datav.aliyun.com/tools/atlas/

// 就是下面 数据结构 的 数组
// {
//     "type": "", // 这个不用管
//     "properties": {}, // 属性, 主要是取里面的内容, 包括区名称, 编号, 中心点经纬度, 级别, 反正有效信息都在这里面了
//     "geometry": {} // 这个数据量太大了, 希望不传输, 只用于搜索
// }

GET beijin/_count

// search: 找出点属于那个区
GET /beijin/_search
{
  "_source": "properties", 
  "query": {
    "bool": {
      "filter": {
        "geo_shape": {
          "geometry": {
            "shape": {
              "type": "point",
              "coordinates": [116.366794, 39.915309]
            },
            "relation": "intersects"
          }
        }
      }
    }
  }
}

// search: 附近的人
GET /beijin/_search
{
    "_source": "properties", 
    "query": {
        "bool": {
            "should": {
                "geo_distance": {
                    "distance": "20km",
                    "properties.center": {
                        "lat": 39.915309,
                        "lon": 116.366794
                    }
                }
            }
        }
    },
    "sort": [
        {
            "_geo_distance": {
                "unit": "km",
                "order": "asc",
                "properties.center": {
                        "lat": 39.915309,
                        "lon": 116.366794
                }
            }
        }
    ]
}